package org.lisa.crm.service;

import org.lisa.crm.dao.CustomerDao;
import org.lisa.crm.dao.CustomerLossDao;
import org.lisa.crm.dao.CustomerOrderDao;
import org.lisa.crm.model.Customer;
import org.lisa.crm.model.CustomerOrder;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Iterator;
import java.util.List;

/**
 * Created by Administrator on 2018/2/7.
 */
/*
    第一步、 查找 创建的时间  超过6个月 的客户      【t_customer】
	第二步、 在订单表 中查询   最近6个月 是否有下单记录。 若没有就是流失客户
	第三步、将流失的客户 存入 t_customer_loss 表
 */
public class TaskScheduleService {

    @Autowired
    private CustomerDao customerDao;


    @Autowired
    private CustomerLossDao customerLossDao;

    @Autowired
    private CustomerOrderDao customerOrderDao;

    public void systemJudegeCustomerLoss() {
        //获取6个月前注册账户
        List<Customer> beforeSixMonthCustomer = customerDao.queryCustomerBeforeSixMonth();

        if (beforeSixMonthCustomer != null && beforeSixMonthCustomer.size() > 0) {
            Iterator<Customer> iterable = beforeSixMonthCustomer.iterator();
            while (iterable.hasNext()) {
                //获取到客户
                Customer customer = iterable.next();
                //查询该客户最近6个月的订单
                List<CustomerOrder> customerOrders = customerOrderDao.queryCusomterOderRecentSixMonth(customer.getId());

            }
        }
    }

    /*
        判断是否符合 流失客户
         */
    public boolean isConformCustomerLoss(List<CustomerOrder> customerOrders) {
        return false;
    }


}

